var pdmOpenWin = function () {

    var action = path + '/action/powerdb/designer/';

    //模块新增修改弹窗和内表单选择器
    var moduleAddOrModifyModalSelector = '#moduleAddOrModifyModal';
    var moduleAddOrEditFormSelector = '#moduleAddOrEditForm';

    var relDbConnInfoModalSelector = '#relDbConnInfoModal';
    var relDbModalSelector = '#relDbModal';

    //数据库连接表格选择器
    var dbConnInfoJqTableSeletor = '#dbInfoJqgridTable';
    var dbConnInfoJqPagerSeletor = '#dbInfoJqgridPager';

    //数据库表格
    var databaseTableSeletor = '#databaseJqgridTable';
    var databasePagerSeletor = '#databaseJqgridPager';
    var databaseSearchFormSeletor = '#databaseSearchForm';

    //数据库新增修改弹窗
    var databaseAddModalSelector = '#databaseAddModal';
    var databaseAddOrEditFormSelector = '#databaseAddOrEditForm';

    //实体新增弹窗选择器
    var entityAddModalSelector = '#entityAddModal';
    var addOrEditFieldJqgridTableSelector = '#addOrEditFieldJqgridTable';
    var addOrEditFieldJqgridPagerSelector = '#addOrEditFieldJqgridPager';
    var entityAddOrEditFormSelector = '#entityAddOrEditForm';

    //版本新增弹窗和内表单选择器
    var versionAddModalSelector = '#versionAddModal';
    var versionAddFormSelector = '#addVersionForm';

    //新增关系模块
    var relAddOrEditModalSelector = '#relAddOrEditModal';
    var relAddOrEditModelFormSelector = '#relAddOrEditModelForm';

    /** 枚举关键字定义 */
    var enums = ['pdm_field-isNull', 'pdm_field-isPmKey', 'pdm_field-autoIncrement',
        'pdm_field-type', 'pd_db_conn_info-status', 'pd_db_conn_info-type',
        'pd_db_conn_info-charset', 'pdm_database-databaseCode'];

    /** 获取所有需要翻译的枚举 */
    var enumMap = sPost.getEnumMap(enums);

    var lastsel;

    //数据库连接信息弹窗，用户选择数据
    var dbConnInfoData = null;

    //数据库信息弹窗，用户选择数据
    var databaseData = null;

    /**
     * select2下拉默认配置
     */
    var select2EnumDef = {
        selector: 'select',
        enums: [],					//枚举对象数组，有enums，则不需要enumKey和map
        enumKey: null,			//枚举关键字'表名-字段名'
        enumMap: null,				//已经查出来的枚举map对象

        /* **************必填分割线，上面必填，下面可选 *************************************/
        width: '200px',
        defVal: null,				//枚举的默认显示值，未实现
        valueField: 'enumCode',		//select的value值字段
        textField: 'enumValue',		//的显示值字段
        textMapField: 'enumMapValue',		//的显示值字段
        useMapTextField: false,	    //是否使用枚举映射值
        select2Option: {},
        addAll: false				//是否添加全部选项

    };


    /**
     * 获取当前登录用户的id
     */
    function getCurAccountId() {
        return accountId;
    }

    function initHeight() {
        var height = $(window).height();
        height = height - (height * 0.03)
        $('.mint_tab').height(height);
        $('#projectExplorer').height(height);
        pdm.umlHeight = height * 0.9;
        console.log('##############' + pdm.umlHeight);
    }

    return {

        /**
         * 将翻译的枚举值放到select2
         */
        select2Enum: function (options) {
            options = $.extend({}, select2EnumDef, options);

            if (options.enums == null) {
                if (options.enumKey != null && options.enumMap != null) {
                    options.enums = options.enumMap.get(options.enumKey);
                } else {
                    console.log(options.selector + ' enumKey和enumMap必须同时存在');
                }
            }

            var arrs = options.enums.concat();

            if (options.addAll) { //添加全部到枚举数组中
                arrs.splice(0, 0,
                    {enumCode: '', enumValue: '全部'});
            }

            var val = options.valueField;
            var text = options.textField;
            if (options.useMapTextField == true) {
                text = options.textMapField;
            }
            var defSelect = 0;
            $(options.selector).html('');
            $.each(arrs, function (index, value) {
                if (value['defStatus'] == 1) {
                    defSelect = value['enumCode'];
                }
                $(options.selector).append('<option value="'
                    + value[val] + '">'
                    + value[text]
                    + '</option>');
                $(options.selector).val(defSelect);
                if (options.addAll) { //默认初始化全部
                    $(options.selector).val('');
                }
            });
        },
        /**
         * 表格的初始化
         */
        init: function () {

            initHeight()

            var url = action + 'field/';

            function initEnum() {
                pdmOpenWin.select2Enum({
                    selector: '#dbStatus',
                    enums: enumMap.get('pd_db_conn_info-status'),
                    addAll: true
                });
                pdmOpenWin.select2Enum({
                    selector: '#dbType',
                    enums: enumMap.get('pd_db_conn_info-type'),
                    addAll: true
                });
                pdmOpenWin.select2Enum({
                    selector: '#dbCharset',
                    enums: enumMap.get('pd_db_conn_info-charset'),
                    addAll: true
                });
                pdmOpenWin.select2Enum({
                    selector: '#dbCode',
                    enums: enumMap.get('pdm_database-databaseCode'),
                    addAll: true
                });
            }

            function initJqGrid(setting) {
                sGrid.jqgridSimple(setting);
                sGrid.jqgridReSize(setting);
                sGrid.jqgridNotButton(setting['gridId'], setting['pagerId']);
                sGrid.jqgridDestory(setting['gridId']);
            }

            initEnum();

            $(addOrEditFieldJqgridTableSelector).tableDnD({
                scrollAmount: 0
            });

            $(addOrEditFieldJqgridTableSelector).jqGrid({
                pager: addOrEditFieldJqgridPagerSelector,
                autowidth: true,
                datatype: 'local',
                height: 130,
                //gridHeightType: 2,
                mtype: 'post',
                multiselect: true,
                rownumbers: true,
                rowNum: 100,
                editurl: url,
                rowList: [5, 15, 25],
                colNames: ['id', '创建时间', '修改时间', '模块id', '项目id',
                    '中文名', '英文名', '字段类型', '长度', '精度',
                    '允许空', '主键', '表id', '是否自增', '脚本', '创建人',
                    '描述', '修改人', '排序', '域', '版本id'],
                colModel: [
                    {name: 'id', index: 'id', width: 0, align: 'center', hidden: true, editable: true},
                    {
                        name: 'createTime',
                        index: 'createTime',
                        width: 0,
                        align: 'center',
                        hidden: true,
                        editable: true
                    },
                    {
                        name: 'modifyTime',
                        index: 'modifyTime',
                        width: 0,
                        align: 'center',
                        hidden: true,
                        editable: true
                    },
                    {
                        name: 'moduleId',
                        index: 'moduleId',
                        width: 0,
                        align: 'center',
                        hidden: true,
                        editable: true
                    },
                    {
                        name: 'projectId',
                        index: 'projectId',
                        width: 0,
                        align: 'center',
                        hidden: true,
                        editable: true
                    },
                    {name: 'nameCn', index: 'nameCn', width: 80, align: 'center', editable: true},
                    {name: 'name', index: 'name', width: 80, align: 'center', editable: true},
                    {
                        name: 'type',
                        index: 'type',
                        width: 80,
                        align: 'center',
                        editable: true,
                        edittype: 'select',
                        editoptions: {value: pdm.getEditoptions(enumMap, enums[3])}
                    },
                    {name: 'length', index: 'length', width: 50, align: 'center', editable: true},
                    {name: 'decimalPoint', index: 'decimalPoint', width: 50, align: 'center', editable: true},
                    {
                        name: 'isNull',
                        index: 'isNull',
                        width: 50,
                        align: 'center',
                        editable: true,
                        edittype: 'select',
                        editoptions: {value: pdm.getEditoptions(enumMap, enums[0])}
                    },
                    {
                        name: 'isPmKey',
                        index: 'isPmKey',
                        width: 50,
                        align: 'center',
                        editable: true,
                        edittype: 'select',
                        editoptions: {value: pdm.getEditoptions(enumMap, enums[1])}
                    },
                    {
                        name: 'entityId',
                        index: 'entityId',
                        width: 0,
                        align: 'center',
                        hidden: true,
                        editable: true
                    },
                    {
                        name: 'autoIncrement',
                        index: 'autoIncrement',
                        width: 80,
                        align: 'center',
                        editable: true,
                        edittype: 'select',
                        editoptions: {value: pdm.getEditoptions(enumMap, enums[2])}
                    },
                    {
                        name: 'script',
                        index: 'script',
                        width: 120,
                        align: 'center',
                        hidden: true,
                        editable: true
                    },
                    {
                        name: 'createAccountId',
                        index: 'createAccountId',
                        width: 0,
                        align: 'center',
                        hidden: true,
                        editable: true,
                    },
                    {
                        name: 'remark',
                        index: 'remark',
                        width: 0,
                        align: 'center',
                        editable: true,
                        edittype: "textarea",
                        editoptions: {rows: "2", cols: "5"}
                    },
                    {
                        name: 'modifyAccountId',
                        index: 'modifyAccountId',
                        width: 0,
                        align: 'center',
                        hidden: true,
                        editable: true,
                        formatter: function () {
                            return getCurAccountId()
                        }
                    },
                    {
                        name: 'sortIndex',
                        index: 'sortIndex',
                        width: 0,
                        align: 'center',
                        hidden: true,
                        editable: true,
                    },
                    {
                        name: 'domain',
                        index: 'domain',
                        width: 50,
                        align: 'center',
                        editable: true,
                    },
                    {
                        name: 'versionId',
                        index: 'versionId',
                        width: 0,
                        align: 'center',
                        hidden: true,
                        editable: true
                    }

                ],
                ondblClickRow: function (id) {
                    if (id) {
                        var data = $(addOrEditFieldJqgridTableSelector).jqGrid("getRowData", id);
                        if (data.versionId != DEFAULT_VERSION_ID) {
                            return;
                        } else {
                            $(addOrEditFieldJqgridTableSelector).jqGrid('restoreRow', lastsel);
                            $(addOrEditFieldJqgridTableSelector).jqGrid('editRow', id,
                            {
                                keys : true,        //这里按[enter]保存
                                restoreAfterError: true,
                                successfunc: function(response){
                                    var json = sUtils.str2Json(response.responseText)[0];
                                    if(json.success) {
                                        return true;
                                    }else{
                                        slog.log(json);
                                        layer.alert(json.msg,{'icon':5,'title':'提示'});
                                        return false;
                                    }
                                }
                            });
                            lastsel = id;

                            //主键下拉框联动
                            $("#" + id + "_isPmKey").change(function () {
                                if ($("#" + id + "_isPmKey").val() == 1) {
                                    $("#" + id + "_isNull").val(2);
                                    $("#" + id + "_autoIncrement").val(1);
                                    $("#" + id + "_type").val(4);
                                    $("#" + id + "_length").val(11);
                                } else {
                                    $("#" + id + "_isNull").val(1);
                                    $("#" + id + "_autoIncrement").val(2);
                                }
                            });

                            //枚举下拉联动
                            $("#" + id + "_type").change(function () {
                                if ($("#" + id + "_type").val() == 2) {
                                    $("#" + id + "_isNull").val(2);
                                    $("#" + id + "_length").val(6);
                                }
                            });
                        }
                    }
                },
                gridComplete: function () {
                    $("#_empty", addOrEditFieldJqgridTableSelector).addClass("nodrag nodrop"); //样式
                    $(addOrEditFieldJqgridTableSelector).tableDnDUpdate(); //更新jquery.tablednd.js插件的方法。
                }
            });

            //数据库连接信息
            var dbConnInfoGridSetting = {
                gridId: dbConnInfoJqTableSeletor,
                pagerId: dbConnInfoJqPagerSeletor,
                // datatype: 'json',
                datatype: 'local',
                data: [],
                //height: 125,
                gridHeightType: 2,
                url: null,
                mtype: "post",
                multiselect: false,
                rownumbers: true,
                autowidth: true,
                rowNum: 5,
                rowList: [5, 15, 30],
                colNames: ['id', '连接名', '数据库名', '存储端口', '存储状态', '存储类型', '编码', '创建人', '修改人', '创建时间', '修改时间', '描述'],
                colModel: [
                    {name: 'id', index: 'id', width: 0, align: 'center', hidden: true},
                    {name: 'name', index: 'name', width: 0, align: 'center'},
                    {name: 'dbName', index: 'dbName', width: 0, align: 'center'},
                    {name: 'port', index: 'port', width: 0, align: 'center'},
                    {name: 'status', index: 'status', width: 0, align: 'center'},
                    {name: 'type', index: 'type', width: 0, align: 'center'},
                    {name: 'charset', index: 'charset', width: 0, align: 'center'},
                    {name: 'createAccount', index: 'createAccount', width: 0, align: 'center'},
                    {name: 'modifyAccount', index: 'modifyAccount', width: 0, align: 'center'},
                    {name: 'createTime', index: 'createTime', width: 0, align: 'center'},
                    {name: 'modifyTime', index: 'modifyTime', width: 0, align: 'center'},
                    {name: 'remark', index: 'remark', width: 0, align: 'center'}
                ]
            };

            //数据库信息
            var dbGridSetting = {
                gridId: databaseTableSeletor,
                pagerId: databasePagerSeletor,
                // datatype: 'json',
                datatype: 'local',
                data: [],
                //height: 165,
                gridHeightType: 2,
                url: null,
                mtype: "post",
                multiselect: false,
                rownumbers: true,
                autowidth: true,
                rowNum: 10,
                rowList: [10, 15, 30],
                colNames: ['id', '数据库名', '中文名', '编码', '创建人', '修改人', '创建时间', '修改时间', '描述'],
                colModel: [
                    {name: 'id', index: 'id', width: 0, align: 'center', hidden: true},
                    {name: 'name', index: 'name', width: 0, align: 'center'},
                    {name: 'nameCn', index: 'nameCn', width: 0, align: 'center'},
                    {name: 'databaseCode', index: 'databaseCode', width: 0, align: 'center'},
                    {name: 'createAccount', index: 'createAccount', width: 0, align: 'center'},
                    {name: 'modifyAccount', index: 'modifyAccount', width: 0, align: 'center'},
                    {name: 'createTime', index: 'createTime', width: 0, align: 'center'},
                    {name: 'modifyTime', index: 'modifyTime', width: 0, align: 'center'},
                    {name: 'remark', index: 'remark', width: 0, align: 'center'}
                ]
            };

            initJqGrid(dbConnInfoGridSetting);
            initJqGrid(dbGridSetting);

            sUtils.formValidClass(moduleAddOrEditFormSelector);
            sUtils.formValidClass(entityAddOrEditFormSelector);
            sUtils.formValidClass(relAddOrEditModelFormSelector);
            sUtils.formValidClass(versionAddFormSelector);
        },

        /**
         * 弹出新增/修改模块窗口
         * @param project
         * @param $tree
         * @param isAdd
         */
        openWinAddOrEditModule: function (project, $tree, isAdd) {

            var resData;

            /* 清空弹窗表单  */
            function cleanOpenWin() {
                sUtils.cleanFrom(moduleAddOrEditFormSelector);
                sUtils.validResetForm(moduleAddOrEditFormSelector);
                //如果有特殊控件，还需要特殊处理；
                dbConnInfoData = null;
                databaseData = null;
            }

            /*
             加载表单数据
             */
            function initOpenWin() {
                var url = action + 'module/';
                sPost.ajaxFind(url, {}, function (data) {
                    if (data.success) {
                        slog.log(data.obj);
                        var modules = data.obj;
                        $.each(modules, function (i, module) {
                            $(moduleAddOrEditFormSelector).find('#highLevelModule')[0].options.add(new Option(module.name, module.id));
                        });
                    } else {
                        slog.error('查询失败' + data.msg);
                    }
                });
            }

            cleanOpenWin();

            if (isAdd) {   //新增
                slog.log('新增');

            } else {
                slog.log('修改');
                /*
                 判断是否选中行
                 获取修改的数据，填充打表单里
                 */
                if (project.type != 'module') {
                    alert("请选择模块！");
                    return;
                }
                var url = action + 'module/' + project.id;

                sPost.ajaxGet(url, function (data) {
                    if (data.success) {
                        slog.log('查找模块成功');
                        slog.log(data.obj);
                        resData = data.obj;
                        sUtils.setFrom(moduleAddOrEditFormSelector, resData);
                    } else {
                        slog.log('查找失败');
                    }
                });
            }
            var title = isAdd ? '新增模块' : '修改模块';
            layer.open({
                type: 1,
                title: title,
                shadeClose: true,
                //shade: 0.8,
                area: ['580px', '335px'],
                content: $(moduleAddOrModifyModalSelector),
                zIndex: 1000,
                btn: ['保存', '取消'],
                yes: function (at, layero) {
                    if (isAdd == true && sUtils.isNull(dbConnInfoData)) {
                        layer.alert("请选择数据库连接信息!", {icon: 5, title: '提示'});
                        return;
                    }

                    if (isAdd == true && sUtils.isNull(databaseData)) {
                        layer.alert("请选择数据库!", {icon: 5, title: '提示'});
                        return;
                    }
                    var result = pdm.saveOrEditModule(project, $tree, isAdd, dbConnInfoData, databaseData);
                    if (result == true) {
                        layer.close(at);
                    }
                }
            });
        },

        /**
         * 弹出新增版本窗口
         */
        openWinAddVersion: function (project, $tree) {

            slog.log(project);

            /*清空弹窗表单*/
            function cleanOpenWin() {
                sUtils.cleanFrom(versionAddFormSelector);
                //sUtils.validResetForm(versionAddFormSelector);
                $(versionAddFormSelector).find('#versionRemark').empty();
            }

            cleanOpenWin();

            layer.open({
                type: 1,
                title: '新增版本',
                shadeClose: true,
                //shade: 0.8,
                area: ['600px', '271px'],
                content: $(versionAddModalSelector),
                zIndex: 1000,
                btn: ['新增', '取消'],
                yes: function (index, layero) {
                    var result = pdm.saveVersion(project, $tree);
                    if (result == true) {
                        layer.close(index);
                    }
                }
            });

        },

        /**
         * 弹出修改实体窗口
         */
        openWinEditEntity: function (nodeData) {

            var versionId;

            /* 清空弹窗表单  */
            function cleanOpenWin() {
                sUtils.cleanFrom(entityAddOrEditFormSelector);
                sUtils.validResetForm(entityAddOrEditFormSelector);
                //如果有特殊控件，还需要特殊处理；
                $(addOrEditFieldJqgridTableSelector).jqGrid('clearGridData');
                $('#myTab li').removeClass("active");
            }

            function initOpenWin() {
                $('#myTab li a[href="#entity"]').tab('show');
                var data = pdm.loadEntityAndField(nodeData);
                if (data != null) {
                    $(addOrEditFieldJqgridTableSelector).setGridParam({data: data});
                    $(addOrEditFieldJqgridTableSelector).trigger("reloadGrid");
                }

                data = sUtils.getFormParams(entityAddOrEditFormSelector);
                versionId = data.versionId;

                //若点击的是版本实体，则隐藏编辑字段按钮
                var list = $("#field").find('button');
                $.each(list, function (idx, val) {
                    versionId == DEFAULT_VERSION_ID ? $(this).show() : $(this).hide();
                });

            }

            cleanOpenWin();
            initOpenWin();

            layer.open({
                type: 1,
                title: '编辑实体',
                shadeClose: true,
                area: ['880px', '400px'],
                content: $(entityAddModalSelector),
                zIndex: 1000,
                btn: ['保存', '取消'],
                yes: function (at, layero) {
                    if (versionId == DEFAULT_VERSION_ID) {
                        $(addOrEditFieldJqgridTableSelector).trigger("reloadGrid");
                        var result = pdm.editEntity(nodeData);
                        if (result == true) {
                            layer.close(at);
                        }
                    } else {
                        layer.alert("旧版本实体不可编辑!", {'icon': 5, 'title': '提示'});
                    }
                }
            });

            //点击新增按钮
            //会导致多次绑定，故先取消绑定后再绑定点击事件
            $('#addField').unbind('click').bind('click', function () {
                slog.log('addField click');
                pdm.saveField(nodeData);
            });

            //点击插入模板按钮
            $('#insertTemplate').unbind('click').bind('click', function () {
                slog.log('insertTemplate click');
                pdm.saveField(nodeData);
            });

            //点击复制按钮
            $('#copyField').unbind('click').bind('click', function () {
                slog.log('copyField click');
                pdm.copyField(nodeData);
            });

            //点击删除按钮
            $('#delField').unbind('click').bind('click', function () {
                slog.log('delField click');
                pdm.delField(nodeData);
            });

            //点击保存顺序按钮
            $('#saveFieldSort').unbind('click').bind('click', function () {
                slog.log('saveFieldSort click');
                pdm.saveFieldSort();
            });
        },

        /**
         * 弹出修改关系窗口
         */
        openWinEditRelate: function (entityRelateId) {

            var $seletor = $(relAddOrEditModelFormSelector);
            var versionId;

            /* 清空弹窗表单  */
            function cleanOpenWin() {
                sUtils.cleanFrom(relAddOrEditModelFormSelector);
                sUtils.validResetForm(relAddOrEditModelFormSelector);
                //如果有特殊控件，还需要特殊处理；
                $seletor.find('#field1').empty();
                $seletor.find('#field2').empty();
            }

            function initOpenWin(data) {
                var url = action + 'field/';
                var params = {
                    'Q_entityId_=_Long': data[0].startObjectId,
                    'Q_versionId_=_Long': data[0].versionId
                };
                sPost.ajaxFind(url, params, function (data) {
                    if (data.success) {
                        slog.log(data.obj);
                        var fields = data.obj;
                        $.each(fields, function (i, field) {
                            var option = $("<option>").val(field.id).text(field.nameCn + '(' + field.name + ')');
                            $('#field1').append(option);
                        });
                    } else {
                        slog.error('查询失败' + data.msg);
                    }
                });
                params = {
                    'Q_entityId_=_Long': data[0].endObjectId,
                    'Q_versionId_=_Long': data[0].versionId
                };
                sPost.ajaxFind(url, params, function (data) {
                    if (data.success) {
                        slog.log(data.obj);
                        var fields = data.obj;
                        $.each(fields, function (i, field) {
                            var option = $("<option>").val(field.id).text(field.nameCn + '(' + field.name + ')');
                            $('#field2').append(option);
                        });
                    } else {
                        slog.error('查询失败' + data.msg);
                    }
                });

                $seletor.find('#entity1').val(data[0]['eNameCn'] + '(' + data[0]['eName'] + ')');
                $seletor.find('#entity2').val(data[1]['eNameCn'] + '(' + data[1]['eName'] + ')');
                $seletor.find('#field1').val(data[0].startFieldId);
                $seletor.find('#field2').val(data[0].endFieldId);

            }

            cleanOpenWin();

            url = action + 'entityRelate/getEntityByEntityRelatId/';
            sPost.ajax(url, {'id': entityRelateId}, function (data) {
                if (data.success) {
                    slog.log('获取关系数据成功');
                    slog.log(data);
                    sUtils.setFrom(relAddOrEditModelFormSelector, data.obj[0]);
                    versionId = data.obj[0].versionId;
                    initOpenWin(data.obj);
                } else {
                    slog.log('获取关系数据失败');
                }
            });

            // layer弹窗按钮
            layer.open({
                type: 1,
                title: '编辑关系',
                shadeClose: true,
                //shade: 0.8,
                area: ['730px', '333px'],
                content: $(relAddOrEditModalSelector),
                zIndex: 1010,
                btn: ['保存', '取消'],
                yes: function (index, layero) {
                    if (versionId == DEFAULT_VERSION_ID) {
                        var result = pdm.editEntityRelate();
                        if (result == true) {
                            layer.close(index);
                        }
                    } else {
                        layer.alert("旧版本关系不可编辑!", {'icon': 5, 'title': '提示'});
                    }
                }
            });
        },

        openWinDbConnInfo: function () {

            slog.log('openWin dbConnInfo');

            dbConnInfo.searchDbConnInfo(false);

            layer.open({
                type: 1,
                title: '选择所属数据库连接信息',
                shadeClose: true,
                //shade: 0.8,
                area: ['900px', '465px'],
                content: $(relDbConnInfoModalSelector),
                zIndex: 1000,
                btn: ['确定', '取消'],
                yes: function (at, layero) {

                    var id = $(dbConnInfoJqTableSeletor).jqGrid('getGridParam', 'selrow');
                    slog.log(id);

                    // 判断是否选中
                    if (sUtils.isNull(id)) {
                        layer.alert('请选择所属的数据库连接信息！', {icon: 5, title: '提示'});
                        return;
                    }
                    dbConnInfoData = $(dbConnInfoJqTableSeletor).jqGrid('getRowData', id);
                    $(moduleAddOrEditFormSelector).find("#relDbConnInfo").val(dbConnInfoData.name);
                    layer.close(at);
                }
            });

            $('#dbConnInfoSearch').unbind('click').bind('click', function () {
                slog.log('dbConnInfoSearch click');
                dbConnInfo.searchDbConnInfo(false);
            });

            $('#dbConnInfoClear').unbind('click').bind('click', function () {
                slog.log('dbConnInfoClear click');
                sUtils.cleanFrom('#dbSearchForm');
                $('#dbStatus').val('');
                $('#dbType').val('');
                $('#dbCharset').val('');
            });
        },

        /**
         * 弹出数据库信息
         */
        openWinDatabase: function () {
            slog.log('openWin database');

            pdm.loadDatabase();

            layer.open({
                type: 1,
                title: '选择所属数据库',
                shadeClose: true,
                //shade: 0.8,
                area: ['900px', '425px'],
                content: $(relDbModalSelector),
                zIndex: 1000,
                btn: ['确定', '取消'],
                yes: function (at, layero) {
                    var id = $(databaseTableSeletor).jqGrid('getGridParam', 'selrow');
                    slog.log(id);

                    // 判断是否选中
                    if (sUtils.isNull(id)) {
                        layer.alert('请选择所属的数据库！', {icon: 5, title: '提示'});
                        return;
                    }
                    databaseData = $(databaseTableSeletor).jqGrid('getRowData', id);
                    $(moduleAddOrEditFormSelector).find("#relDatabase").val(databaseData.name);
                    layer.close(at);
                }
            });

            $('#databaseSearch').unbind('click').bind('click', function () {
                slog.log('databaseSearch click');
                database.searchDatabase(false);
            });

            $('#databaseClear').unbind('click').bind('click', function () {
                slog.log('databaseClear click');
                sUtils.cleanFrom(databaseSearchFormSeletor);
                $('#addDbCode').val('');
                database.searchDatabase(false);
            });

            $('#databaseAdd').unbind('click').bind('click', function () {
                slog.log('databaseAdd click');
                database.openWinDbAddOrEdit(true);
            });
        }
    }
}();

